{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import sys\n",
    "import sqlite3\n",
    "sys.path.append(os.path.dirname(os.path.abspath('')))\n",
    "from scene.colmap_loader import read_extrinsics_text, read_intrinsics_text, qvec2rotmat, \\\n",
    "    read_extrinsics_binary, read_intrinsics_binary, read_points3D_binary, read_points3D_text\n",
    "\n",
    "path = '../data/UE-collected/aerial/block1_20'\n",
    "\n",
    "db_path = os.path.join(path, \"distorted/database.db\")\n",
    "bin_path = os.path.join(path, \"sparse/0/points3D.bin\")\n",
    "cameras_extrinsic_file = os.path.join(path, \"sparse/0\", \"images.bin\")\n",
    "cameras_intrinsic_file = os.path.join(path, \"sparse/0\", \"cameras.bin\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "def dict_factory(cursor, row):\n",
    "    d = {}\n",
    "    for idx, col in enumerate(cursor.description):\n",
    "        d[col[0]] = row[idx]\n",
    "    return d"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[{'name': 'cameras'}, {'name': 'sqlite_sequence'}, {'name': 'images'}, {'name': 'sqlite_autoindex_images_1'}, {'name': 'index_name'}, {'name': 'keypoints'}, {'name': 'descriptors'}, {'name': 'matches'}, {'name': 'two_view_geometries'}]\n",
      "Done\n"
     ]
    }
   ],
   "source": [
    "cam_extrinsics = read_extrinsics_binary(cameras_extrinsic_file)\n",
    "cam_intrinsics = read_intrinsics_binary(cameras_intrinsic_file)\n",
    "xyz, rgb, _ = read_points3D_binary(bin_path)\n",
    "\n",
    "conn = sqlite3.connect(db_path)\n",
    "conn.row_factory = dict_factory\n",
    "c = conn.cursor()\n",
    "c.execute(\"select name from sqlite_master \")\n",
    "output = c.fetchall()\n",
    "print (output)\n",
    "data = c.execute(\"select * from images\").fetchall()\n",
    "print('Done')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "gaussian_splatting",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.12"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
